package dbi

import (
	"github.com/go-xorm/xorm"
	"github.com/olivere/elastic/v7"
	"gluenet/pkg/meta"
	"gluenet/pkg/ops/impl/helm"
	"gluenet/pkg/ops/impl/influxdb"
)

type GlueDB interface {
	Connect() error
	Close() error
	MetaDB() *xorm.Engine
	LogsDB() *influxdb.Client
	MetricDB() *influxdb.Client
	//GetStatus(sql string, retData interface{}) error

	//GetK8sNodes(sql string, retData interface{}) error
	//GetK8sPodContainers(sql string, retData interface{}) error
	//GetK8sContainerInfo(sql string, retData interface{}) error
	HelmCharts(name string) ([]*helm.Result, error)
	HelmRepoUpdates() error

	GetTracesK8s(guid string, start, end, limit int64, retData interface{}) error
	GetTracesId(id string, retData interface{}) error
	GetTracesGluenets(guid string, containers []string, start, end, limit int64, retData interface{}) error
	GetLogs(sql string, retData interface{}) error
	//CreateTable(dataBase string, data interface{}) error
	//DropTable(dataBase string, data interface{}) error
	//QueryOne(sql string, dataBase string, retData interface{}) error
	//QueryList(sql string, dataBase string, retData interface{}) error
	//Update(dataBase string, data interface{}) (int64, error)
	//UpdateSql(sql string, dataBase string, retData interface{}) (int64, error)
	//UpdateByLabel(dataBase string, tableName, label, guid string, data interface{}) (int64, error)
	//Delete(dataBase string, data interface{}) (int64, error)
	//InsertOne(dataBase string, data interface{}) (int64, error)

	ConfigGet(platform string, label string, data **meta.Config) error
	ConfigKindList(kind string, data *[]meta.Config) error
	ConfigList(platform string, kind string, data *[]meta.Config) error
	ConfigListAll(data *[]meta.Config) error
	ConfigDel(label string) error

	InstanceGet(guid string, data **meta.Instance) error
	InstanceList(platform string, kind string, data *[]meta.Instance) error
	InstanceKindList(kind string, data *[]meta.Instance) error
	InstanceListAll(data *[]meta.Instance) error
	InstanceDel(guid string) error
	InstanceRuntimeGet(guid string, data **meta.InstanceRunTime) error
	InstanceRuntimeList(data *[]meta.InstanceRunTime) error
	InstanceRuntimePut(data *meta.InstanceRunTime) error
	InstanceRuntimeContainerUpdate(guid string, containers string) error
	InstanceRuntimeContainerInfoUpdate(guid string, infos string) error
	InstanceRuntimeContainerTracesGet(guid string, data *string) error
	InstanceRuntimeContainerTracesUpdate(guid string, data string) error
	InstanceRuntimeStatusUpdate(guid string, status string) error
	InstanceStatusGet(guid string, data **meta.InstanceStatus) error

	AgentGet(guid string, data **meta.Agent) error
	AgentListAll(data *[]meta.Agent) error
	AgentRuntimeGet(guid string, data **meta.AgentRunTime) error
	AgentRuntimeList(data *[]meta.AgentRunTime) error
	AgentRuntimePut(data *meta.AgentRunTime) error
	AgentRuntimeContainersUpdate(guid string, containers string) error
	AgentRuntimeHostUpdate(guid string, hosts string) error
	AgentRuntimeStatusUpdate(guid string, status string) error

	ScheduleResultGet(guid string, data **meta.ScheduleResults) error
	ScheduleResultPut(data *meta.ScheduleResults) error
	ScheduleResultDel(guid string) error

	StrategyLinksGet(guid string, data **meta.StrategyLinks) error
	StrategyUnLinksGet(guid string, data *[]string) error
	StrategyLinksPut(data *meta.StrategyLinks) error

	MapGet(data **meta.Tree) error
	MapPut(data *meta.Tree) error

	DagGet(root string, data **meta.Dag) error
	DagPut(root string, data *meta.Dag) error

	UpdateState(platform string, guid string) error
	UpdateTrace(platform string, guid string) error

	MetricsInstancesList(kind string, data **meta.MetricsInstancesList) error
	MetricsList(data **meta.Metrics) error
	MetricsQuery(object, platform, metric, guid, child string, start, end int64, data **meta.Metrics) error
	MetricsSumQuery(object, platform, metric, guid string, child string, start, end int64, data **meta.Metrics) error
	MetricsMethodQuery(object, platform, metric, guid, method string, start, end int64, data **meta.Metrics) error
	MetricsQuerySpecial(title string, kind string, guid string, child string, start, end int64, data **meta.Metrics) error
	MetricsQuerySQL(sql string, data interface{}) error
	MetricsServiceMeshQuery(title, guid, platform string, data **meta.Metrics) error
	MetricsPut(data interface{}) error

	//InfosQuery(title string, guid string, data **meta.Info, args ...string) error

	LogsCounts(platform string, guid string, container string, start, stop, bucket string, data **meta.Logs) error
	LogsQuery(platform string, guid string, container string, start, stop string, data **meta.Logs) error
	LogsPut(data interface{}) error

	TracesPut(data interface{}) error
	//Transaction() GlueDBSession

	GetIndex(data *string) error
	PutIndex(index string) error

	// GetESClient Get ElasticSearch client for next operation
	GetESClient() *elastic.Client
}

//type GlueDBSession interface {
//	CreateTable(data interface{}) error
//	QueryOne(sql string, retData interface{}) error
//	QueryList(sql string, retData interface{}) error
//	Update(data interface{}) (int64, error)
//	Delete(data interface{}) (int64, error)
//	InsertOne(data interface{}) (int64, error)
//	InsertList(data interface{}) (int64, error)
//	Rollback() error
//	Commit() error
//}
